 
package com.hs;

import java.util.HashMap;
import java.util.Map;

import javax.activation.DataHandler;

import com.hs.log.HsLogger;

/**
 * <code>HsBase</code> is loaded as a singleton class and provides access
 * to all core wiki structures.  In addition this class provides utility methods
 * for resetting core structures including caches and permissions.
 *
 * @see org.jamwiki.DataHandler
 * @see org.jamwiki.UserHandler
 * @see org.jamwiki.search.SearchEngine
 */
public class HsBase {
    private static Map sqlMap = null;
	/** Standard logger. */
	private static final HsLogger logger = HsLogger.getLogger(HsBase.class.getName());
	/** The singleton instance of this class. */
	private static HsBase instance = null;
	/** The data handler that looks after read/write operations. */
	private static DataHandler dataHandler = null;
	/** The handler for user login/authentication. */
//	private static UserHandler userHandler = null;
//	/** The search engine instance. */
//	private static SearchEngine searchEngine = null;

	/** Cache name for the cache of parsed topic content. */
	public static final String CACHE_PARSED_TOPIC_CONTENT = "org.jamwiki.WikiBase.CACHE_PARSED_TOPIC_CONTENT";
	/** Ansi data handler class */
	public static final String DATA_HANDLER_ANSI = "org.jamwiki.db.AnsiDataHandler";
	/** DB2 data handler class */
	public static final String DATA_HANDLER_DB2 = "org.jamwiki.db.DB2DataHandler";
	/** DB2/400 data handler class */
	public static final String DATA_HANDLER_DB2400 = "org.jamwiki.db.DB2400DataHandler";
	/** HSql data handler class */
	public static final String DATA_HANDLER_HSQL = "org.jamwiki.db.HSqlDataHandler";
	/** MSSql data handler class */
	public static final String DATA_HANDLER_MSSQL = "org.jamwiki.db.MSSqlDataHandler";
	/** MySql data handler class */
	public static final String DATA_HANDLER_MYSQL = "org.jamwiki.db.MySqlDataHandler";
	/** Oracle data handler class */
	public static final String DATA_HANDLER_ORACLE = "org.jamwiki.db.OracleDataHandler";
	/** Postgres data handler class */
	public static final String DATA_HANDLER_POSTGRES = "org.jamwiki.db.PostgresDataHandler";
	/** Sybase ASA data handler class */
	public static final String DATA_HANDLER_ASA = "org.jamwiki.db.SybaseASADataHandler";
	/** Data stored using an external database */
	public static final String PERSISTENCE_EXTERNAL = "DATABASE";
	/** Data stored using an internal copy of the HSQL database */
	public static final String PERSISTENCE_INTERNAL = "INTERNAL";
	/** Lucene search engine class */
	public static final String SEARCH_ENGINE_LUCENE = "org.jamwiki.search.LuceneSearchEngine";
	/** Allow file uploads of any file type. */
	public static final int UPLOAD_ALL = 0;
	/** Use a blacklist to determine what file types can be uploaded. */
	public static final int UPLOAD_BLACKLIST = 2;
	/** Disable all file uploads. */
	public static final int UPLOAD_NONE = 1;
	/** Use a whitelist to determine what file types can be uploaded. */
	public static final int UPLOAD_WHITELIST = 3;
	/** Database user handler class */
	public static final String USER_HANDLER_DATABASE = "org.jamwiki.db.DatabaseUserHandler";
	/** LDAP user handler class */
	public static final String USER_HANDLER_LDAP = "org.jamwiki.ldap.LdapUserHandler";

	static {
		try {
			HsBase.instance = new HsBase();
		} catch (Exception e) {
			logger.severe("Failure while initializing WikiBase", e);
		}
	}

	/**
	 * Creates an instance of <code>WikiBase</code>, initializing the default
	 * data handler instance and search engine instance.
	 *
	 * @throws Exception If the instance cannot be instantiated.
	 */
	private HsBase() throws Exception {
		sqlMap = new HashMap();
		//this.reload();
	}

	/**
	 * Get an instance of the current data handler.
	 *
	 * @return The current data handler instance, or <code>null</code>
	 *  if the handler has not yet been initialized.
	 */
//	public static DataHandler getDataHandler() {
//		return HsBase.instance;
//	}

//	/**
//	 * Get an instance of the current search engine.
//	 *
//	 * @return The current search engine instance.
//	 */
//	public static SearchEngine getSearchEngine() {
//		return WikiBase.HsBase;
//	}
//
//	/**
//	 *
//	 */
//	public static UserHandler getUserHandler() {
//		return WikiBase.HsBase;
//	}

//	/**
//	 * Reload the data handler, user handler, and other basic wiki
//	 * data structures.
//	 */
//	public static void reload() throws Exception {
//		WikiBase.HsBase = WikiUtil.dataHandlerInstance();
//		WikiBase.HsBase = WikiUtil.userHandlerInstance();
//		WikiBase.HsBase = WikiUtil.searchEngineInstance();
//	}

	/**
	 * Reset the WikiBase object, re-initializing the data handler and
	 * other values.
	 *
	 * @param locale The locale to be used if any system pages need to be set up
	 *  as a part of the initialization process.
	 * @param user A sysadmin user to be used in case any system pages need to
	 *  be created as a part of the initialization process.
	 * @throws Exception Thrown if an error occurs during re-initialization.
	 */
//	public static void reset(Locale locale, WikiUser user) throws Exception {
//		HsBase.instance = new HsBase();
//		WikiCache.initialize();
//		WikiBase.HsBase.setup(locale, user);
//	}
//	public static String getUrl(){
//		String url = null;
//		ResourceBundle messages = ResourceBundle.getBundle("SSOConfig");
//		if(null != messages)
//			url = messages.getString("ssoUrl");
//		return url;
//			
//	}
	public static Map getAnsiSqlMap(){
		return sqlMap;
	}
}
